package com.baizhi.service;

import com.baizhi.annotations.RedisCache;
import com.baizhi.dao.PictureMapper;
import com.baizhi.entity.Picture;
import com.baizhi.entity.PictureExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("pictureService")
@Transactional
public class PictureServiceImpl implements PictureService{

    @Resource
    private PictureMapper pictureMapper;
    @Override
    @RedisCache
    public List<Picture> findAll() {
        PictureExample pictureExample = new PictureExample();

        return pictureMapper.selectByExample(pictureExample);
    }

    @Override
    @RedisCache
    public Picture findByPrimaryId(String id) {
        return pictureMapper.selectByPrimaryKey(id);
    }

    @Override
    @RedisCache
    public List<Picture> findById(String id) {
        PictureExample pictureExample = new PictureExample();
        pictureExample.createCriteria().andProductidEqualTo(id);
        return pictureMapper.selectByExample(pictureExample);
    }

    @Override
    public void save(Picture picture) {
        pictureMapper.insert(picture);
    }

    @Override
    public void update(Picture picture) {
        pictureMapper.updateByPrimaryKey(picture);
    }

    @Override
    public void delete(String id) {
        pictureMapper.deleteByPrimaryKey(id);
    }
}
